package com.example.myapplication3;

import android.content.Context;
import android.content.SharedPreferences;

public class TokenManager {
    private static final String PREF_NAME = "user_prefs";
    private static final String KEY_TOKEN = "token";
    private SharedPreferences sp;

    public TokenManager(Context context) {
        sp = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }

    // 保存Token
    public void saveToken(String token) {
        sp.edit().putString(KEY_TOKEN, token).apply();
    }

    // 获取Token
    public String getToken() {
        return sp.getString(KEY_TOKEN, "");
    }

    // 判断是否已登录
    public boolean isLoggedIn() {
        return !getToken().isEmpty();
    }
}